package com.hjh.webdemo.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hjh.webdemo.entity.User;
import com.hjh.webdemo.mapper.UserMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public User login(String userCode, String userPassword) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userCode",userCode);
        queryWrapper.eq("userPassword",userPassword);
        return userMapper.selectOne(queryWrapper);
    }

    @Transactional
    @Override
    public int addUser(User user) {
        return 0;
    }

    @Override
    public int deleteUser(Integer id) {
        return userMapper.deleteById(id);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateById(user);
    }

    @Override
    public User getUser(Integer id) {
        return userMapper.selectById(id);
    }

    @Override
    public List<User> findAllUsers() {
        return userMapper.selectList(null);
    }
}
